/**
 * 
 */
package org.jenkon.comparator;

import java.io.Serializable;
import java.util.Comparator;

/**
 * Implementation of comparator to reversing the arguments of the {@link #compare(Object, Object)}
 * method.
 * 
 * @author Jens Konopka
 * 
 * @param <T> type of the comparator value objects
 */
public class ReverseComparator<T> implements Comparator<T>, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6354528697401129644L;

	/**
	 * the decorating comparator.
	 */
	private final Comparator<T> comparator;

	/**
	 * Create a new instance of this comparator.
	 * 
	 * @param comparator {@link Comparator}
	 */
	public ReverseComparator(final Comparator<T> comparator) {
		this.comparator = comparator;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(final T o1, final T o2) {
		return comparator.compare(o2, o1);
	}

}
